<{include file="Toy/toy_top.html"}>
    </head>
    <body>
    	<div id="wrap">
			<{include file="Toy/toy_nav.html"}>
    		
    		<div class="container dealPage">
    			<!--未进行任何交易-->
    			<div class="nodata" style="display:none">您还未进行任何交易</div>
    			<ul>

					<{foreach from=$list item=item}>
						<li>
							<a href="<{u('detail?itemId='|cat:$item.mainItem)}>">
							<div class="img-box">
								<div class="toy">
									<img src="<{$item.mainHeadPic}>" alt="" />
								</div>
								<p class="nickname"><{$item.mainNickname}></p>
							</div>
							</a>
							<{if $item.status eq $statusAgree}>
								<div class="detail state-2">
									<p class="state">同意交换</p>
									<div class="line <{if $item.slaveUid eq $mainUid}>reverse<{/if}>"></div>
									<p class="phone">(对方号码:
										<{if $item.mainUid eq $mainUid}>
											<{$userPhone[$item.slaveUid]}>
										<{else}>
											<{<{$userPhone[$item.mainUid]}>}>
										<{/IF}>
										)</p>
								</div>
							<{elseif $item.status eq $statusRefuse}>
								<div class="detail state-3">
									<p class="state">拒绝交换</p>
									<div class="line <{if $item.slaveUid eq $mainUid}>reverse<{/if}>"></div>
									<p class="phone">(确认交换后显示联系方式)</p>
								</div>
							<{elseif $item.status eq $statusWait}>
								<{if $item.mainUid eq $mainUid}>
									<div class="detail state-1-2">
										<p class="state">
											<a href="javascript:void(0);" class="agree" onclick="agree(this,<{$item.id}>)">同意</a>
											<a href="javascript:void(0);" class="deny"  onclick="refuse(this,<{$item.id}>)">拒绝</a>
										</p>
										<div class="line reverse"></div>
										<p class="phone">(确认交换后显示联系方式)</p>
									</div>
								<{else}>
									<div class="detail state-1">
										<p class="state">兑换申请中，等待对方答复</p>
										<div class="line"></div>
										<p class="phone">(确认交换后显示联系方式)</p>
									</div>
								<{/if}>
							<{/if}>

							<a href="<{u('detail?itemId='|cat:$item.slaveItem)}>">
							<div class="img-box">
								<div class="toy">
									<img src="<{$item.slaveHeadPic}>" alt="" />
								</div>
								<p class="nickname"><{$item.slaveNickname}></p>
							</div>
							</a>

							<div class="btn-group">
								<{if $item.status eq $statusRefuse}>
									<a href="javascript:void(0);" onclick="deleteTrade(this,<{$item.id}>)" class="del"></a>
								<{/if}>
								<{if $item.status eq $statusAgree}>
									<a href="<{u('feedback?id='|cat:$item.id)}>" class="" style="font-size: 0.3rem">评价</a>
								<{/if}>
							</div>
						</li>
					<{/foreach}>
    			</ul>
    		</div>

			<{include file="Toy/toy_foot.html"}>
    	</div>
    	<script src="<{$preStaticUrl}>Wap/toy/js/zepto.min.js"></script>
    	<script src="<{$preStaticUrl}>Wap/toy/js/index.js"></script>

	<script>
		function refuse(obj,recordId) {
			$.post("<{u('refuse')}>",{recordId: recordId},function(ret){
				if(ret.status==0){
					$(obj).parent().html("拒绝交换").parent().removeClass("state-1-2").addClass('state-3');
				}else{

				}
			},'json');
		}
		function agree(obj,recordId) {
			$.post("<{u('agree')}>",{recordId: recordId},function(ret){
				if(ret.status==0){
					$(obj).parent().html("同意交换").parent().removeClass("state-1-2").addClass('state-2').find('.phone').text("（对方号码:"+ret.phone+"）");
				}else{

				}
			},'json');
		}

		function deleteTrade(obj,tradeId){
			var $obj=$(obj);
			$.ajax({
				type:"post",
				url:"<{u('deleteTrade')}>",
				dataType: 'json',
				data: {id:tradeId},
				success: function(data){
					if(data.status==0){
						$obj.parents('li').remove();
					}
					tip(data.msg);
				}
			});
		}
	</script>
	</body>
</html>
